﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BookShelf.Model.Tests
{
    /// <summary>
    /// Summary description for AuthorTest
    /// </summary>
    [TestClass]
    public class AuthorTest
    {

        private int authorID = 0;
        private string firstName = "John";
        private string middleName = "F.";
        private string lastName = "Doe";

        public AuthorTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestAuthorConstructor()
        {
            Author author = new Author(authorID, firstName, middleName, lastName);

            Assert.AreEqual(authorID, author.ID);
            Assert.AreEqual(firstName, author.FirstName);
            Assert.AreEqual(middleName, author.MiddleName);
            Assert.AreEqual(lastName, author.LastName);
        }

        [TestMethod, ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void TestAuthorConstructorWithInvalidID()
        {
            Author author = new Author(-1, firstName, middleName, lastName);
        }

        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void TestAuthorConstructorWithEmptyFirstName()
        {
            Author author = new Author(authorID, string.Empty, middleName, lastName);
        }

        [TestMethod, ExpectedException(typeof(ArgumentNullException))]
        public void TestAuthorConstructorWithEmptyLastName()
        {
            Author author = new Author(authorID, firstName, middleName, string.Empty);
        }

        [TestMethod]
        public void TestAuthorSetUrl()
        {
            Author author = new Author(authorID, firstName, middleName, lastName);
            string oldUrl = author.Url;
            string newUrl = "http://www.yahoo.com";

            author.SetUrl(newUrl);

            Assert.AreNotEqual(author.Url, oldUrl);
            Assert.AreEqual(author.Url, newUrl);
        }

    }
}
